# coding:utf-8

"""
CopyRight(c)  2017-09-15  Fraplus Corp

Author: Weilin Shen, Xiaodong.yang
Email:  xiaodong.yang@unidt.com
Functions:

we chat server

dependence package:

fralog
handler

"""

# from workerfunc.downhead import DownHead
# import redis
#
# dh = DownHead()
#
# dh.addJob( 'Hell01')
# dh.addJob( 'Hello2')

import etcd
from playhouse.db_url import connect
from playhouse.shortcuts import dict_to_model, model_to_dict

#
#
# client = etcd.Client(host='120.132.101.30', port=2379)
# # client.set('/nodes/n1', 1)
# try:
#     n = client.get('/nodes/n1')
#     print(n.value)
# except etcd.EtcdException as e:
#     print(e)

from peewee import *

mysql_config_url = 'mysql+pool://root:jim123@127.0.0.1:3306/testit?max_connections=300&stale_timeout=300'
db = connect(url=mysql_config_url)


class UnknownField(object):
    pass


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    class Meta:
        db_table = 'user_copy'

    username = CharField()
    nick_name = CharField()
    password = CharField()


with db.execution_context():
    qq = User.nick_name == '土豆' or User.username == '4@qq.com'
    query = User.select().where(qq).order_by(User.id.desc()).paginate(1, 20)  # .offset(1).limit(1)
    for pet in query:
        print(model_to_dict(pet))
